package com.polito.mad.bikeponyapp.persistence;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;

public abstract class Repository<T,K extends DAO<T>> extends DAOProxy<T, K>{

	protected Repository(Context ctx,K dao) throws Exception {
		super(dao);
		modelObservers = new ArrayList<ModelObserver>();
	}
	
	private List<ModelObserver> modelObservers;
	
	public void registerObserver(ModelObserver observer)
	{
		this.modelObservers.add(observer);
	}
	public void unregisterObserver(ModelObserver observer)
	{
		this.modelObservers.remove(observer);
	}
	public void unregisterAll()
	{
		this.modelObservers.clear();
	}
	
	@Override
	protected void notifyModelChanged() {
		for(ModelObserver observer: modelObservers)
			observer.dataSetChanged();
	}
	@Override
	protected void notifyResourcesClosed() {
		for(ModelObserver observer: modelObservers)
			observer.releaseRepositoryConnection();
		
	}
	public void release()
	{
	}

}
